#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/10/26
# @Author  : 邓大大
# @Desc    : ccxt 框架学习

import ccxt
import pandas as pd
print(ccxt.exchanges)  # 框架集成的可调用的交易所ID
# # ccxt.binance()  # 根据ID 调用交易所
#
#
# binance_exchange = ccxt.binance(   # 初始化交易所
#     {
#         'timeout': 15000,        # 访问超时时间，单位（sm）
#         'enableRateLimit': True,  # 限制访问频率
#         'proxies': {
#             'http': 'http://127.0.0.1:58591',
#             'https': 'https://127.0.0.1:58591'}
#     }
# )
#
# # print(binance_exchange.iso8601(binance_exchange.milliseconds()))
# # binance_markets = binance_exchange.load_markets()
# # print(len(list(binance_markets)))
# symbol = 'BTC/USDT'
# # print(binance_mar kets[symbol])
#
# # ticker 数据
# ticker_data = binance_exchange.fetch_ticker(symbol)
# print(ticker_data)
# # order_book = binance_exchange.fetch_order_book(symbol)
# # # 最高买家
# # high_p = order_book['bids'][0][0] if len(order_book['bids']) > 0 else None
# # # 最低卖价
# # low_p = order_book['asks'][0][0] if len(order_book['asks']) > 0 else None
# #
# # sprad = (low_p - high_p) if (high_p and low_p) else None
#
# # print(binance_exchange.last_response_headers['Date'])
# # print('买价: {:.2f}, 卖价：{:.2f}, 价差:{:.2f}'.format(high_p,low_p,sprad))
#
# if binance_exchange.has.get('fetchOHLCV'):
#     kline_data = pd.DataFrame(binance_exchange.fetch_ohlcv(symbol, timeframe='1m'))
#     kline_data.columns = ['Datetime', 'Open', 'High', 'Low', 'Close', 'Vol']
#     kline_data['Datetime'] = kline_data['Datetime'].apply(binance_exchange.iso8601)
#     print(kline_data.head())
#     print(kline_data.shape)
